<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="pragma" content="no-cache"/>
    <meta http-equiv="content-type" content="no-cache, must-revalidate"/>
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT"/>
    <title>汽车评价</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/my.css" rel="stylesheet">
    <link href="css/nav.css" rel="stylesheet">

    <style>
        [v-cloak] {
            display: none;
        }
        td{
            vertical-align: middle !important;
        }
    </style>
</head>
<body class="beij">
<div id="wrapper" v-cloak>
    <!-- 头部开始 -->
    <div style="width: 100%; height: 60px; line-height: 60px; background: rgb(100 152 231)">
        <div class="container">
            <div class="row">
                <div class="col-md-4">
                    <div style="color: rgb(100 152 231); font-size: 20px;">汽车租赁系统</div>
                </div>
                <div class="col-md-4"></div>
                <div class="col-md-2">
                    <span v-if="user.name" style="color: #eee;">
                        <span style="color: rgb(100 152 231); margin-right: 20px">{{user.name}}</span>
                        <a style="color: #eee;" href="javascript:void(0)" @click="logout">退出</a>
                        <a style="color: #eee;" v-if="isCollect" style="margin-left: 10px" href="collectInfo.html">收藏夹</a>
                    </span>
                </div>
                <div class="col-md-2" style="text-align: right">
                    <a href="/end/page/login.html" target="_blank" style="color: #eee; margin-right: 10px">登录</a>
                    <a href="/end/page/register.html" target="_blank" style="color: #eee;">注册</a>
                </div>
            </div>

        </div>
    </div>
    <!-- 导航开始 -->
    <div class="container" style="margin: 5px auto">
        <div style="width: 100%; height: 50px; line-height: 50px;">
            <div class="col-md-12" style="padding: 0">
                <div class="row">
                    <ul style="display: flex;">
                        <li class="nav-item"><a href="index.html">首页</a></li>
                        <li class="nav-item"><a href="advertiserInfo.html">通知管理</a></li>
			<li class="nav-item"><a href="messageInfo.html">留言板</a></li>
			<li class="nav-item"><a href="submitInfo.html">事故检查</a></li>
			<li class="nav-item"><a href="richtextInfo.html">政策信息宣传</a></li>
			<li class="nav-item"><a href="cartInfo.html">预约单信息</a></li>
			<li class="nav-item"><a href="orderInfo.html">订单信息</a></li>
			<li class="nav-item active"><a href="commentInfo.html">评价信息</a></li>

                        <li class="nav-item"><a href="javascript:void(0)" @click="personalPage">个人信息</a></li>
                        <li class="nav-item" v-if="isShow"><a href="/end/page/index.html" target="_blank">进入后台系统</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <!-- 导航结束 -->
    <!-- 头部结束 -->
    <div class="container"  style="margin-top: 20px">
        <div class="col-md-12">
            <table class="table table-striped table-bordered table-hover">
                <thead>
                <tr style="background-color: #eee6e6">
                    <th>汽车</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="(item,index) in goodsList" :key="item.id">
                    <td style="width:230px;">
                        <a style="margin-bottom: 5px; display: flex;align-items: center" :href="'/front/goodsInfo.html?goodsId=' + item.id" target="_blank">
                            <img style="width: 50%; height: 50%" :src=item.imgSrc>
                            <span style="font-size: 12px; margin-left: 10px">{{item.name}}</span>
                        </a>
                    </td>
                    <td>{{item.commentStatus}}</td>
                    <td>
                        <button class="btn btn-primary btn-xs" @click="openModel(item)">评价</button>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div class="modal" tabindex="-1" role="dialog" id="commentModal">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <span class="modal-title">请填写信息</span>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="form-horizontal">
                        <input type="hidden" name="id" v-model="commentInfo.goodsId">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">评价内容</label>
                            <div class="col-sm-7">
                                <textarea type="text" class="form-control" v-model="commentInfo.content" placeholder="请输入评价内容"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" @click="submitComment()">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.metisMenu.js"></script>
<script src="js/vue2.6.11/vue.min.js"></script>
<script src="js/vue2.6.11/axios.js"></script>
<script src="js/my.js"></script>

<script>
    new Vue({
        el: '#wrapper',
        data: {
            isCollect: false,
            goodsList: [],
            commentInfo: {
                goodsId: 0,
                content: ''
            },
            user: {},
            isShow: false
        },

        created: function() {
            this.loadGoodsInfo();
        },

        methods: {
            loadGoodsInfo() {
                axios.get('/auth').then(res => {
                    if (res.data.code === '0') {
                        this.user = res.data.data;
                        if (this.user.level !== 3) {
                            this.isShow = true;
                        }
                        axios.get("/goodsInfo/comment/" + this.user.id + "/" + this.user.level).then(res => {
                            if (res.data.code === '0') {
                                let goodsList = res.data.data;
                                goodsList.forEach(item => {
                                    // 获取展示图
                                    item.imgSrc = '/front/img/goods/default.png';
                                    if (item.fileIds) {
                                        let fileIds = JSON.parse(item.fileIds);
                                        if (fileIds.length) {
                                            item.imgSrc = '/files/download/' + fileIds[0];
                                        }
                                    }
                                });
                                this.goodsList = goodsList;
                            } else {
                                alert(res.data.msg);
                            }
                        });
                    } else {
                        alert('请先登录');
                        location.href = '/end/page/login.html';
                    }
                })
            },
            openModel(data) {
                this.commentInfo.goodsId = data.id;
                this.commentInfo.content = '';
                $('#commentModal').modal('show');
            },
            submitComment() {
                let data = {userId: this.user.id, level: this.user.level, content: this.commentInfo.content, goodsId: this.commentInfo.goodsId};
                axios.post('/commentInfo', data).then(res => {
                    if (res.data.code === '0') {
                        $('#commentModal').modal('hide');
                        alert('评价成功');
                        this.loadGoodsInfo();
                    } else {
                        alert(res.data.msg);
                    }
                })
            },
            logout() {
                axios.get("/logout").then(res => {
                    if(res.data.code === '0') {
                        location.href = '/front/index.html';
                    } else {
                        msg('error', res.data.msg);
                    }
                })
            }
        }
    })
</script>
</body>
</html>
